<?php
namespace Controllers;
use Models\Category;
use Models\News;

class NewsController extends CommonController {
    public function lists() {
        $category_id = $_GET['id'];
        $categoryModel = new Category();
        $categories = $categoryModel->getAllCategory();
        $data['categories'] = $categories;
        $newsModel = new News();
        $items = $newsModel->getNewsByCategoryId($category_id);
        $data['items'] = $items;
        return $this->render('news/lists', $data);
    }

    public function detail () {
        $id = $_GET['id'];
        $categoryModel = new Category();
        $categories = $categoryModel->getAllCategory();
        $data['categories'] = $categories;
        $newsModel = new News();
        $news = $newsModel->getNewsById($id);
        $data['news'] = $news;
        return $this->render('news/detail', $data);
    }
}